from stark.service.stark import StarkConfig, Option
from crm_app.permission.base import BASERbacPermission


class ClassListConfig(BASERbacPermission, StarkConfig):
    """课程管理"""
    def display_title(self, row=None, header=False):
        if header:
            return "班级"
        return "%s-%s期" % (row.course.name, row.semester)

    def display_start_date(self, row=None, header=False):
        if header:
            return "开班日期"
        return row.start_date.strftime("%Y-%m-%d")

    list_display = ["id", display_title, "school", display_start_date]
    list_filter = [
        Option(field="school", is_choices=False, is_multi=False, text_func=lambda x:x.title, value_func=lambda x:x.pk),
        Option(field="course", is_choices=False, is_multi=False, text_func=lambda x:x.name, value_func=lambda x:x.pk),
    ]